﻿
namespace SomethingSpacial.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.Web.DomainServices;
    using System.Web.DomainServices.Providers;
    using System.Web.Ria;
    using System.Web.Ria.Services;


    // Implements application logic using the SomethingSpacialEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class SomethingSpacialService : LinqToEntitiesDomainService<SomethingSpacialEntities>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Events> GetEvents()
        {
            return this.ObjectContext.Events;
        }

        public IQueryable<Events> GetEventLatest()
        {
            return this.ObjectContext.Events.OrderByDescending(e => e.EVT_Start_Date).Take(1);
        }

        public IQueryable<Events> GetEventsPrevious()
        {
            return this.ObjectContext.Events.OrderByDescending(e => e.EVT_Start_Date);
        }


        public void InsertEvents(Events events)
        {
            this.ObjectContext.AddToEvents(events);
        }

        public void UpdateEvents(Events currentEvents)
        {
            if ((currentEvents.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentEvents, this.ChangeSet.GetOriginal(currentEvents));
            }
        }

        public void DeleteEvents(Events events)
        {
            if ((events.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(events);
            }
            this.ObjectContext.DeleteObject(events);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Locations> GetLocations()
        {
            return this.ObjectContext.Locations;
        }

        public void InsertLocations(Locations locations)
        {
            this.ObjectContext.AddToLocations(locations);
        }

        public void UpdateLocations(Locations currentLocations)
        {
            if ((currentLocations.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentLocations, this.ChangeSet.GetOriginal(currentLocations));
            }
        }

        public void DeleteLocations(Locations locations)
        {
            if ((locations.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(locations);
            }
            this.ObjectContext.DeleteObject(locations);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Sponsors> GetSponsors()
        {
            return this.ObjectContext.Sponsors;
        }

        public void InsertSponsors(Sponsors sponsors)
        {
            this.ObjectContext.AddToSponsors(sponsors);
        }

        public void UpdateSponsors(Sponsors currentSponsors)
        {
            if ((currentSponsors.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentSponsors, this.ChangeSet.GetOriginal(currentSponsors));
            }
        }

        public void DeleteSponsors(Sponsors sponsors)
        {
            if ((sponsors.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(sponsors);
            }
            this.ObjectContext.DeleteObject(sponsors);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<UserGroups> GetUserGroups()
        {
            return this.ObjectContext.UserGroups;
        }

        public IQueryable<UserGroups> GetUserGroupsFirst()
        {
               return this.ObjectContext.UserGroups.OrderByDescending(e => e.UG_Id).Take(1);
        }


        public void InsertUserGroups(UserGroups userGroups)
        {
            this.ObjectContext.AddToUserGroups(userGroups);
        }

        public void UpdateUserGroups(UserGroups currentUserGroups)
        {
            if ((currentUserGroups.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentUserGroups, this.ChangeSet.GetOriginal(currentUserGroups));
            }
        }

        public void DeleteUserGroups(UserGroups userGroups)
        {
            if ((userGroups.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(userGroups);
            }
            this.ObjectContext.DeleteObject(userGroups);
        }
    }
}


